package com.woniu.cq.medical.dao;

import com.woniu.cq.medical.controller.form.PrescriptionInfoForm;
import com.woniu.cq.medical.controller.form.ProjectForm;
import com.woniu.cq.medical.controller.form.RegisterAllForm;
import com.woniu.cq.medical.entity.Prescription;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Lucas
 * @since 2020-09-08
 */
public interface PrescriptionMapper extends BaseMapper<Prescription> {

    @Select("select pr.`status`,p.patient_id,p.patient_name,c.case_id,c.prescription_id,m.product_name,cf.medicine_number,cf.medicine_price,\n" +
            "cf.medicine_total from lonbon_patient p left join lonbon_case c\n" +
            "on p.patient_id=c.user_id \n" +
            "left join lonbon_prescription pr on c.prescription_id=pr.prescription_id\n" +
            "left join lonbon_prescription_info cf \n" +
            "on pr.prescription_id=cf.prescription_id left join \n" +
            "lonbon_medicine m on cf.medicine_id=m.medicine_id\n" +
            " where p.patient_id_card=#{patientIdCard} and pr.`status`='未支付'")
    List<PrescriptionInfoForm> selectProduct(String patientIdCard);

    @Select("select ca.check_apply_id,p.patient_id,p.patient_name,c.case_id,pt.project_name as project_type_name,pi.project_name,\n" +
            "pi.project_price,cap.check_apply_project_info_id,ca.check_charge_pay_status from lonbon_patient p left join lonbon_case c\n" +
            "on p.patient_id=c.user_id left join lonbon_check_apply ca on c.case_id=ca.case_id\n" +
            "left join lonbon_check_apply_project_info cap \n" +
            "on cap.check_apply_id=ca.check_apply_id\n" +
            "left join lonbon_project_info pi on cap.project_info_id=pi.project_info_id\n" +
            "left join lonbon_project_type pt on pi.project_type_id=pt.project_type_id \n" +
            "where p.patient_id_card=#{patientIdCard} and ca.check_charge_pay_status='未支付'")
    List<ProjectForm> selectProject(String patientIdCard);

    @Select("select p.patient_id,p.patient_name,c.case_id,c.prescription_id,m.product_name,cf.medicine_number,cf.medicine_price,\n" +
            "cf.medicine_total,pr.`status` from lonbon_patient p left join lonbon_case c\n" +
            "on p.patient_id=c.user_id \n" +
            "left join lonbon_prescription pr on c.prescription_id=pr.prescription_id\n" +
            "left join lonbon_prescription_info cf \n" +
            "on pr.prescription_id=cf.prescription_id left join \n" +
            "lonbon_medicine m on cf.medicine_id=m.medicine_id\n" +
            " where p.patient_id_card=#{patientIdCard} and c.prescription_id is not null")
    List<PrescriptionInfoForm> selectProductAll(String patientIdCard);

    @Select("\n" +
            "select ca.check_apply_id,p.patient_id,p.patient_name,c.case_id,pt.project_name as project_type_name,pi.project_name,\n" +
            "pi.project_price,cap.check_apply_project_info_id,ca.check_charge_pay_status\n" +
            " from lonbon_patient p left join lonbon_case c\n" +
            "on p.patient_id=c.user_id left join lonbon_check_apply ca on c.case_id=ca.case_id\n" +
            "left join lonbon_check_apply_project_info cap \n" +
            "on cap.check_apply_id=ca.check_apply_id\n" +
            "left join lonbon_project_info pi on cap.project_info_id=pi.project_info_id\n" +
            "left join lonbon_project_type pt on pi.project_type_id=pt.project_type_id \n" +
            "where p.patient_id_card=#{patientIdCard}")
    List<ProjectForm> selectProjectAll(String patientIdCard);

    @Select("select p.patient_name,p.patient_id,c.charge_record_cause,c.charge_record_date \n" +
            "from lonbon_charge_record c left join lonbon_patient p on p.patient_id_card=c.patient_card_id\n" +
            "where c.charge_record_cause like '挂号' and c.patient_card_id=#{patientIdCard}")
    List<RegisterAllForm> selectRegister(String patientIdCard);
}
